import java.awt.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;


public class Test {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
//        //线程池是动态的，cache缓存用了之后不立即释放
//        ExecutorService service= Executors.newCachedThreadPool();
//        //固定创建几个线程
//        ExecutorService service1=Executors.newFixedThreadPool(3);
//        //相当于定时器，但不是一个扫描线程进程操作而是多个线程了
//        ExecutorService service2=Executors.newScheduledThreadPool(4);
//        //固定只有一个线程
//        ExecutorService service3=Executors.newSingleThreadExecutor();
        Callable<Integer> callable=new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                int sum=0;
                for (int i=0 ;i<=100;i++){
                    sum+=i;
                }
                return sum;
            }
        };
        FutureTask<Integer> futureTask=new FutureTask<Integer>(callable);
        Thread t=new Thread(futureTask);
        t.start();
        System.out.println(futureTask.get());
    }
}
